﻿<Window x:Class="ResourceBlender_Express.WinDuplicateResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:ResourceBlender_Express"
    xmlns:props="clr-namespace:ResourceBlender_Express.Properties"
    xmlns:converters="clr-namespace:ResourceBlender_Express.Converters"
    loc:WindowService.EscapeClosesWindow="True"
    Title="Duplicate Resources" WindowStartupLocation="CenterOwner"
    MinHeight="300" Height="500" MinWidth="400" Width="600"
    Style="{StaticResource {x:Type Window}}" Icon="/ResourceBlender-Express;component/Resources/images/resourceblender.ico">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="NavigationCommands.Refresh" Executed="RefreshResources" CanExecute="CanExecuteRefreshResources" />
        <CommandBinding Command="loc:ResourceBlenderCommands.ShowDuplicateDetails" Executed="ShowDuplicateDetails" CanExecute="CanExecuteShowDuplicateDetails"  />
    </Window.CommandBindings>
    <Window.Resources>
        <converters:WidthConverter x:Key="WidthConverter" />
        <converters:DuplicateFormatter x:Key="DuplicateFormatter" />
        <Image x:Key="Details_16" Source="pack://application:,,,/Resources/images/details_16.png" />
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <DockPanel DockPanel.Dock="Top" LastChildFill="True" HorizontalAlignment="Stretch" Width="Auto">
            <ToolBar DockPanel.Dock="Right" BorderThickness="0,0,1,1">
                <loc:ImageButton Command="ApplicationCommands.Help" Text="Help" Image="Resources/images/question_24.png" ToolTip="Show Help" Style="{StaticResource ToolBarButton}" />
            </ToolBar>
            <ToolBar DockPanel.Dock="Left" BorderThickness="1,0,0,1">
                <loc:ImageButton Command="loc:ResourceBlenderCommands.ShowDuplicateDetails" Text="View details" Image="Resources/images/details_32.png" ToolTip="View duplicate details" Style="{StaticResource ToolBarButton}" />
            </ToolBar>
        </DockPanel>
        
        <StatusBar DockPanel.Dock="Bottom">
            <StatusBarItem x:Name="lblStatus" Visibility="Hidden">Loading</StatusBarItem>
            <ProgressBar x:Name="prgStatus" Visibility="Hidden" IsIndeterminate="True" />
        </StatusBar>
        
        <StackPanel DockPanel.Dock="Top" Margin="6">
            <Label>Language</Label>
            <ListBox x:Name="lstLanguages" SelectionChanged="RefreshResources" SelectedValuePath="Key" ItemTemplate="{StaticResource LanguageListItem}" 
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" GridViewColumnHeader.Click="OnColumnHeaderClick">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.Style>
                    <Style BasedOn="{StaticResource RadioListTemplate}" TargetType="ListBox">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBox">
                                    <Border Name="Border" Background="{TemplateBinding Background}" CornerRadius="2"
                                        BorderBrush="{StaticResource SolidBorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                        <ScrollViewer Margin="0" Focusable="false">
                                            <UniformGrid Margin="2" Columns="3" IsItemsHost="True" VerticalAlignment="Top" />
                                        </ScrollViewer>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.Style>
            </ListBox>
        </StackPanel>
        
        <ListView DockPanel.Dock="Bottom" x:Name="lstDuplicates" Margin="6,0,6,6" ItemsSource="{Binding}" SelectedValuePath="translation"  SelectionMode="Single" GridViewColumnHeader.Click="OnColumnHeaderClick">
            <ListView.Resources>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="TextTrimming" Value="CharacterEllipsis" />
                </Style>
            </ListView.Resources>
            <ListView.View>
                <GridView x:Name="grdDuplicates">
                    <GridViewColumn Header="Translation" Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListView}},Converter={StaticResource WidthConverter},ConverterParameter=200}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate DataType="translation">
                                <TextBlock Text="{Binding translation}" ToolTip="{Binding translation}" HorizontalAlignment="Left" VerticalAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="Resources with identical translations" MaxHeight="45" VerticalAlignment="Center" HorizontalAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.HeaderTemplate>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate DataType="number">
                                <StackPanel VerticalAlignment="Center">
                                    <TextBlock Text="{Binding number}" VerticalAlignment="Center" HorizontalAlignment="Center">
                                        <TextBlock.ToolTip>
                                            <MultiBinding Converter="{StaticResource DuplicateFormatter}" ConverterParameter="There are {0} resources with identical {1} translations">
                                                <Binding Path="number" />
                                                <Binding ElementName="lstLanguages" Path="SelectedValue" />
                                            </MultiBinding>
                                        </TextBlock.ToolTip>
                                    </TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="_View Details" Icon="{StaticResource Details_16}" Command="loc:ResourceBlenderCommands.ShowDuplicateDetails" CommandParameter="{Binding translation}" />
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
    </DockPanel>
</Window>
